<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>即将过期订单</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css" />
		<script type="text/javascript" src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/jquery-2.1.0.js"></script>
		<script type="text/javascript" src="../js/mobile-detect.min.js"></script>
		<script type="text/javascript" src="../js/config.js"></script>
		<script type="text/javascript" src="../js/common.js"></script>
		<style type="text/css">
			.mui-media-body {
				position: relative;
			}

			.logo {
				margin-top: 30px;
			}

			.go_jiesuan {
				position: absolute;
				right: 10px;
				top: 50%;
				margin-top: -8px;
				font-size: 14px;
				color: green;
			}

			.mui-table-view-cell {
				padding: 10px 0 !important;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">即将过期订单</h1>
		</header>
		<!--下拉刷新容器-->
		<div class="mui-content">
			<div id="pullrefresh">
				<ul class="mui-table-view mui-table-view-chevron" id="list">
					<script type="text/html" id="model">
						{{if status=="success"}}
						{{each data as value i}}
						<li class="mui-table-view-cell" data-orderNum="{{value.out_order_no}}" data-authNo="{{value.auth_no}}">
							<img class="mui-media-object mui-pull-left logo" src="../img/{{value.pay_type}}.png" style="padding: 10px;">
							<div class="mui-media-body">
								<p><label>消费时间：</label>{{value.created_at}}</p>
								<p><label>消费账户：</label>{{value.payer_logon_id}}</p>
								<p><label>交易订单：</label>{{value.out_order_no}}</p>
								<p><label>预授权金额：</label><span style="color:red;">{{value.amount}}</span>元</p>
								<p class="mui-ellipsis"><label>备注信息：</label>{{value.fu_remark}}</p>
								<span class="go_jiesuan">可结算</span>
							</div>
						</li>
						{{/each}}
						{{/if}}
					</script>
				</ul>
			</div>
		</div>
		<script type="text/javascript" src="../js/template-web.js"></script>
		<script>
			mui.plusReady(function() {
// 				var count = 1; //页码
// 				var page_number = 8; //每页的数据数 
// 				var ws = plus.webview.currentWebview();
				mui.init({
					pullRefresh: {
						container: '#pullrefresh',
						down: {
							style: 'circle',
							callback: pulldownRefresh
						},
						up: {
							auto: true,
							contentrefresh: '正在加载...',
							callback: pullupRefresh
						}
					}
				});
				var ws = plus.webview.currentWebview();
				var pay_status=ws.pay_status?ws.pay_status:"";
				var count = 1;
				var page_number = 10;
				//上拉数据渲染
				function pullupRefresh() {
					require(weburl + waitCheck, "json", "post", {
						token: localStorage.getItem("token"),
						offset: count++,
						limit: page_number,
						pay_status: pay_status
					}, function(response) {
						console.log(JSON.stringify(response));
						console.log(response.data.length);
						console.log(response.status);
						// (response.status == "error") || 
						if ((response.status == "error") || (response.data.length == 0)) {
							console.log('11');
							//参数为true代表没有更多数据了。
							mui('#pullrefresh').pullRefresh().endPullup(true);
							mui.toast(response.msg, {
								duration: 'long',
								type: 'div'
							})
							return false;
						}
                        console.log('22');
						if (response.data.length < page_number) {
							mui('#pullrefresh').pullRefresh().endPullup(true);
							upAddData(response);
							

							return false;
						}
						console.log('33');
						setTimeout(function() {
							mui('#pullrefresh').pullRefresh().endPullup(false); //参数为true代表没有更多数据了。
							upAddData(response);
						}, 1500);
					}, function() {
						mui.toast('网络错误', {
							duration: 'long',
							type: 'div'
						})
					})
					mui('#pullrefresh').pullRefresh().endPullup(false);
				}
				/**
				 * 下拉刷新具体业务实现
				 */
				function pulldownRefresh() {
					count = 1;
					require(weburl + waitCheck, "json", "post", {
						token: localStorage.getItem("token"),
						offset: count++,
						limit: page_number,
						pay_status: pay_status
					}, function(response) {
						console.log(JSON.stringify(response));
                        setTimeout(function() {
                        	downAddData(response);
                        	mui('#pullrefresh').pullRefresh().endPulldown();
// 							// 重置上拉加载
							// mui('#pullrefresh').pullRefresh().refresh(true);
                        }, 1500);					
					}, function() {
						mui.toast('网络错误', {
							duration: 'long',
							type: 'div'
						})
					})
					
				}

				//数据渲染
				//上拉数据渲染
				function upAddData(resData) {
					var str = template("model", resData);
					console.log(str);
					$("#list").append(str);
				}
				// 下拉
				function downAddData(resData) {
					//清空记录
					$("#list").html("");
					var str = template("model", resData);
					$("#list").html(str);
				}
				//点击对应订单跳到详情页
				mui("body").on("tap", "#list .mui-table-view-cell", function() {
					console.log(1);
					mui.openWindow({
						url: "depositDetail.html",
						id: "depositDetail.html",
						extras: {
							authNo: $(this).attr("data-authNo"),
							orderNum: $(this).attr("data-orderNum")
						}
					})
				})
			})
		</script>
	</body>

</html>
